#region Copyright RenGuiYou. All rights reserved.
//=====================================================
// NeatlyFrameWork
// Author:      RenGuiyou
// Feedback: 	mailto:750539605@qq.com
//=====================================================
#endregion

using System;
using System.Text;

public static class NStringBuilder
{
    [ThreadStatic]
    private static StringBuilder _cache = new StringBuilder();

    private const int MAX_BUILDER_SIZE = 512;

    public static StringBuilder Acquire(int capacity = 256)
    {
        StringBuilder cache = _cache;
        if (cache != null && cache.Capacity >= capacity)
        {
            _cache = null;
            cache.Clear();
            return cache;
        }
        return new StringBuilder(capacity);
    }

    public static string GetStringAndRelease(StringBuilder sb)
    {
        string arg_0C_0 = sb.ToString();
        Release(sb);
        return arg_0C_0;
    }

    public static void Release(StringBuilder sb)
    {
        if (sb.Capacity <= MAX_BUILDER_SIZE)
        {
            _cache = sb;
        }
    }
}
